﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinList.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win list.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using System.Linq;

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win list.
    /// </summary>
    public class CuitWinList : CuitWinControl<WinList>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinList" /> class.
        /// </summary>
        public CuitWinList()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinList"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinList(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinList"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinList(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinList"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinList(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinList"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinList(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinList"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinList(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets the checked indices.
        /// </summary>
        public int[] CheckedIndices
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.CheckedIndices;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(string.Join(",", value));
                this._control.CheckedIndices = value;
            }
        }

        /// <summary>
        ///     Gets or sets the checked items.
        /// </summary>
        public string[] CheckedItems
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.CheckedItems;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(string.Join(",", value));
                this._control.CheckedItems = value;
            }
        }

        /// <summary>
        ///     Gets the columns.
        /// </summary>
        public UITestControlCollection Columns
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Columns;
            }
        }

        /// <summary>
        ///     Gets the horizontal scroll bar.
        /// </summary>
        public UITestControl HorizontalScrollBar
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.HorizontalScrollBar;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is checked list.
        /// </summary>
        public bool IsCheckedList
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsCheckedList;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is icon view.
        /// </summary>
        public bool IsIconView
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsIconView;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is list view.
        /// </summary>
        public bool IsListView
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsListView;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is multiple selection.
        /// </summary>
        public bool IsMultipleSelection
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsMultipleSelection;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is report view.
        /// </summary>
        public bool IsReportView
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsReportView;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is small icon view.
        /// </summary>
        public bool IsSmallIconView
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsSmallIconView;
            }
        }

        /// <summary>
        ///     Gets the items.
        /// </summary>
        public string[] Items
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Items.Cast<string>().ToArray();
            }
        }

        /// <summary>
        ///     Gets or sets the selected item as string.
        /// </summary>
        public string SelectedItemAsString
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectedItemsAsString;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value);
                this._control.SelectedItemsAsString = value;
            }
        }

        /// <summary>
        ///     Gets or sets the selected items.
        /// </summary>
        public string[] SelectedItems
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectedItems;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(string.Join(",", value));
                this._control.SelectedItems = value;
            }
        }

        /// <summary>
        ///     Gets the vertical scroll bar.
        /// </summary>
        public UITestControl VerticalScrollBar
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.VerticalScrollBar;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The item exists.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ItemExists(string text)
        {
            this._control.WaitForControlReady();
            return this.Items.Contains(text);
        }

        #endregion
    }
}